package edu.gdut.thesissys.action.director;

import java.util.Date;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.gdut.thesissys.action.BaseAction;
import edu.gdut.thesissys.service.GraduationScheduleService;

/**
 * 规定表上时间
 * 
 * @author gauze
 * 
 */
public class GraduationScheduleAction extends BaseAction {

	private static final Logger log = LoggerFactory
			.getLogger(GraduationScheduleAction.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 5204976837180713399L;

	@Resource
	private GraduationScheduleService graduationScheduleService;

	private Object result;
	private Integer majorId;
	private String graduationGrade;
	private Date paperTitleDate;
	private Date doubleChooseStartDate;
	private Date doubleFirstChooseEndDate;
	private Date doubleChooseEndDate;
	private Date choosePapetTitleDate;
	private Date taskBookStartDate;
	private Date taskBookEndDate;
	private Date midCheckDate;
	private Date accreditationOneStartDate;
	private Date accreditationOneEndDate;
	private Date accreditationTwoStartDate;
	private Date accreditationTwoEndDate;
	private Date publicDebateStartDate;
	private Date publicDebateEndDate;
	private Date commonDabateStartDate;
	private Date commonDabateEndDate;

	/**
	 * 保存或更新表上时间
	 * 
	 * @return
	 */
	public String updateScheduleExecute() {
		log.info("update Schedule");
		this.result = graduationScheduleService.saveOrUpdateSchedule(this);
		log.info("update end, data: " + result.toString());
		return SUCCESS;
	}

	/**
	 * 查询表上时间
	 * 
	 * @return
	 */
	public String findScheduleExecute() {
		log.info("find schedule [" + this.majorId + ", " + this.graduationGrade
				+ "]");
		this.result = graduationScheduleService.getScheduleJson(this);
		log.info("find end, data: " + result.toString());
		return SUCCESS;
	}

	public void validateUpdateScheduleExecute() {
		this.result = new Object();
		if (this.accreditationOneEndDate == null
				|| this.accreditationOneStartDate == null
				|| this.accreditationTwoEndDate == null
				|| this.accreditationTwoStartDate == null
				|| this.choosePapetTitleDate == null
				|| this.commonDabateEndDate == null
				|| this.commonDabateStartDate == null
				|| this.graduationGrade == null || this.majorId == null
				|| this.midCheckDate == null || this.midCheckDate == null
				|| this.paperTitleDate == null
				|| this.publicDebateEndDate == null
				|| this.publicDebateStartDate == null
				|| this.taskBookEndDate == null
				|| this.taskBookStartDate == null) {
			this.addActionError("error params");
			log.info("save or update schedule failed beacause of error params");
			// 非信管系专业，双选不能为空
		} else if (!graduationScheduleService.isXinguan(this.majorId)
				&& (this.doubleChooseEndDate == null
						|| this.doubleChooseStartDate == null || this.doubleFirstChooseEndDate == null)) {
			this.addActionError("error params");
			log.info("save or update schedule failed beacause of error params");
		}
	}

	public void validateFindScheduleExecute() {
		this.result = new Object();
		if (this.majorId == null || this.graduationGrade == null
				|| this.graduationGrade.trim().equals("")) {
			this.addActionError("error params");
			log.info("find schedule failed beacause of error params");
		}
	}

	@JSON(serialize = false)
	public Integer getMajorId() {
		return majorId;
	}

	public void setMajorId(Integer majorId) {
		this.majorId = majorId;
	}

	@JSON(serialize = false)
	public String getGraduationGrade() {
		return graduationGrade;
	}

	public void setGraduationGrade(String graduationGrade) {
		this.graduationGrade = graduationGrade;
	}

	@JSON(serialize = false)
	public Date getPaperTitleDate() {
		return paperTitleDate;
	}

	public void setPaperTitleDate(Date paperTitleDate) {
		this.paperTitleDate = paperTitleDate;
	}

	@JSON(serialize = false)
	public Date getDoubleChooseStartDate() {
		return doubleChooseStartDate;
	}

	public void setDoubleChooseStartDate(Date doubleChooseStartDate) {
		this.doubleChooseStartDate = doubleChooseStartDate;
	}

	@JSON(serialize = false)
	public Date getDoubleFirstChooseEndDate() {
		return doubleFirstChooseEndDate;
	}

	public void setDoubleFirstChooseEndDate(Date doubleFirstChooseEndDate) {
		this.doubleFirstChooseEndDate = doubleFirstChooseEndDate;
	}

	@JSON(serialize = false)
	public Date getDoubleChooseEndDate() {
		return doubleChooseEndDate;
	}

	public void setDoubleChooseEndDate(Date doubleChooseEndDate) {
		this.doubleChooseEndDate = doubleChooseEndDate;
	}

	@JSON(serialize = false)
	public Date getChoosePapetTitleDate() {
		return choosePapetTitleDate;
	}

	public void setChoosePapetTitleDate(Date choosePapetTitleDate) {
		this.choosePapetTitleDate = choosePapetTitleDate;
	}

	@JSON(serialize = false)
	public Date getTaskBookStartDate() {
		return taskBookStartDate;
	}

	public void setTaskBookStartDate(Date taskBookStartDate) {
		this.taskBookStartDate = taskBookStartDate;
	}

	@JSON(serialize = false)
	public Date getTaskBookEndDate() {
		return taskBookEndDate;
	}

	public void setTaskBookEndDate(Date taskBookEndDate) {
		this.taskBookEndDate = taskBookEndDate;
	}

	@JSON(serialize = false)
	public Date getMidCheckDate() {
		return midCheckDate;
	}

	public void setMidCheckDate(Date midCheckDate) {
		this.midCheckDate = midCheckDate;
	}

	@JSON(serialize = false)
	public Date getAccreditationOneStartDate() {
		return accreditationOneStartDate;
	}

	public void setAccreditationOneStartDate(Date accreditationOneStartDate) {
		this.accreditationOneStartDate = accreditationOneStartDate;
	}

	@JSON(serialize = false)
	public Date getAccreditationOneEndDate() {
		return accreditationOneEndDate;
	}

	public void setAccreditationOneEndDate(Date accreditationOneEndDate) {
		this.accreditationOneEndDate = accreditationOneEndDate;
	}

	@JSON(serialize = false)
	public Date getAccreditationTwoStartDate() {
		return accreditationTwoStartDate;
	}

	public void setAccreditationTwoStartDate(Date accreditationTwoStartDate) {
		this.accreditationTwoStartDate = accreditationTwoStartDate;
	}

	@JSON(serialize = false)
	public Date getAccreditationTwoEndDate() {
		return accreditationTwoEndDate;
	}

	public void setAccreditationTwoEndDate(Date accreditationTwoEndDate) {
		this.accreditationTwoEndDate = accreditationTwoEndDate;
	}

	@JSON(serialize = false)
	public Date getPublicDebateStartDate() {
		return publicDebateStartDate;
	}

	public void setPublicDebateStartDate(Date publicDebateStartDate) {
		this.publicDebateStartDate = publicDebateStartDate;
	}

	@JSON(serialize = false)
	public Date getPublicDebateEndDate() {
		return publicDebateEndDate;
	}

	public void setPublicDebateEndDate(Date publicDebateEndDate) {
		this.publicDebateEndDate = publicDebateEndDate;
	}

	@JSON(serialize = false)
	public Date getCommonDabateStartDate() {
		return commonDabateStartDate;
	}

	public void setCommonDabateStartDate(Date commonDabateStartDate) {
		this.commonDabateStartDate = commonDabateStartDate;
	}

	@JSON(serialize = false)
	public Date getCommonDabateEndDate() {
		return commonDabateEndDate;
	}

	public void setCommonDabateEndDate(Date commonDabateEndDate) {
		this.commonDabateEndDate = commonDabateEndDate;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public Object getResult() {
		return result;
	}
}
